package com.neutech.controller;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.neutech.po.Dept;
import com.neutech.po.User;
import com.neutech.service.UserService;
@Controller
/*@Controller能让spring容器将该类扫描成为控制器类*/
@RequestMapping(value="/his")
public class UserController {
	@Autowired
	private UserService userService;
	@RequestMapping("/getUserId")
	public@ResponseBody User getUser(Integer id){
		User user=userService.getUser(id);
		return user;
	}
	@RequestMapping(value="/updateUser",method=RequestMethod.POST)
	public @ResponseBody void updateUser() throws Exception{
		userService.updateUser();	
	}
	@RequestMapping("/deleteUser")
	public @ResponseBody  void deleteUser(Integer id){
		userService.deleteUser(id);		
	}
	@RequestMapping("/addUser")
	public @ResponseBody void addUser(){
		userService.addUser();		
	}
	/*-----------------------------------------------------------*/
	/*@RequestMapping(value="/login",method=RequestMethod.GET)
	@RequestMapping用于建立请求url和处理请求方法间的对应关系
	public ModelAndView login(Model model,@RequestParam(value="username",
	defaultValue="no")String name){
		System.out.println("来♂:"+name);
		ModelAndView mv = new ModelAndView();
		//将数据添加进作用域
		mv.addObject("键名", "无敌");
		//指定返回的网页页面
		mv.setViewName("main");
		model.addAttribute("键名", "空条承太郎");
		return mv;
	}
	@RequestMapping(value="/addUser",method=RequestMethod.POST)
	public String addUser(List<User>user){
		System.out.println(user.get(0).getUsername()+
				"、"+user.get(0).getSex());
		return"main";
	}
	public String addUser(User user){
		System.out.println(user.getUsername()+"、"+user.getSex());
		return "main";
	}
	@RequestMapping(value="updateUser")
	public String addUser(Dept dept){
		System.out.println(dept.getUser().getUsername());
		return"main";
	}
	@RequestMapping(value="/selectUser",method=RequestMethod.POST)
	public String selectUser(@RequestParam(value="userid",defaultValue="0") Integer[]userid){
		for(Integer id:userid){
			System.out.println(id);
		}
		return "";
	}
	@RequestMapping(value="/delUser",method=RequestMethod.POST)
	public String adduser(@RequestParam(value="nameList")List
			<String>nameList){
		for(String u:nameList){
			System.out.println(u);
		}
		return "main";
	}
	@RequestMapping(value="/delAllUser",method=RequestMethod.POST)
	public String delAllUser(@RequestParam Map<String,String>nameList){
		System.out.println(nameList.size());
		Map的循环,以下两种方式
		Set<String>keyset=nameList.keySet();
		for(String s:keyset){
			System.out.println(s+":"+nameList.get(s));
		}
		for(Map.Entry<String, String>set:nameList.entrySet()){
			System.out.println(set.getKey()+"+and+"+set.getValue());
		}
		return "";
	}
	@RequestMapping(value="/delAllUserJSON",method=RequestMethod.POST)
	public String delAllUserJSON(@RequestBody Map<String,String>nameList){

		System.out.println(nameList.size());
		for(Map.Entry<String, String>set:nameList.entrySet()){
			System.out.println(set.getKey()+"and"+set.getValue());
		}
		return "";
	}
	@RequestMapping(value="/addAllUserJsonMap",method=RequestMethod.POST)
		public String addAllUserJsonMap(@RequestBody List<Map<String,String>>nameList){
			System.out.println(nameList.size());
			for(Map<String,String>u:nameList){
				for(Map.Entry<String, String>set:u.entrySet()){
					System.out.println(set.getKey()+":"+set.getValue());
				}
			}
			return "main";
		}*/
}

